#pragma once
#include "interfaces.h"
#include "GameView.h"
#include "SceneManager.h"
#include "Events.h"
#include "RandomEngine.h"
#include "EventManager.h"
#include "RenderComponent.h"
#include <map>
//-------------------------------------------------------------------------------------------------------
//Input Map. Stores which keys are up and which are down + what they mean
//-------------------------------------------------------------------------------------------------------
typedef std::map< unsigned char , bool> KeyMap; // key to is it pressed?
typedef std::map< GameAction, unsigned char > ActionMap; // action to key
class InputMap : public IInputMap
{
public:
	InputMap() { m_mouse_x = 0; m_mouse_y = 0; }
	~InputMap() {}
	
	bool VIsTrue(const GameAction action);
	void VKeyDown(const unsigned char key);
	void VKeyUp(const unsigned char key);
	void VSetActionKey(const GameAction action, const unsigned char key);
	void VResetActionMap();
	GameAction VIsActionMapped(const unsigned char key);

	KeyMap m_keymap; // maps the keyboard buttons
	int m_mouse_x, m_mouse_y; // maps the mouse related events
	bool m_mouse_r, m_mouse_l;
	ActionMap m_actionmap;
};
class BaseController : public IController
{
public:
	BaseController() { }
	~BaseController() { }
	virtual void VOnActionDown(GameAction action);
	virtual void VOnActionUp(GameAction action);
	virtual void VOnUpdate();
	virtual IInputMap* VGetInputMap();
	IInputMap* m_inputmap;
};

class HumanViewListener;
typedef std::list<ScreenElementPtr> ScreenElementList;
//special global value for fast compare
class HumanView : public BaseGameView
{
	friend HumanViewListener;
public:
	 HumanView();
	 HumanView(ActorId id) : BaseGameView(id) { HumanView(); };

	 ~HumanView();

	virtual void VOnRender();
	virtual void VOnUpdate(float fTime);
	void ProcessKeyDown(const unsigned char key);
	void ProcessKeyUp(const unsigned char key);
protected:
	//members
	EventListenerPtr m_Listener; // event listener
	ScreenElementList m_ScreenElementList; // screen elements
	IScene * m_pScene; // current scene
	ISceneNode* m_pcamera;
	ControllerList m_controllers;
	InputMap m_inputmap;
public:
	static GameAction* cm_GameAction_NoAction;
};

class HumanViewListener : public IEventListener
{
	friend HumanView;
public:
	HumanViewListener() {}
	HumanViewListener(HumanView * View) : m_View(View) {}
	~HumanViewListener() {};

	virtual void HandleEvent(EventDataPtr EventData);
private:
	HumanView * m_View;
};